<?php

include('includes/basic.php');

$company_name=addslashes($_POST['name']);
$contactname=addslashes($_POST['contactname']);
$uname=$_POST['uname'];
$password=$_POST['password'];
$pass_encoded=md5($password);
$mob=$_POST['mob'];
$add=addslashes($_POST['add']);
$cust_desc=addslashes($_POST['cust_desc']);




//$recordstatus=$_POST['recordstatus'];





		$sql="insert into customer_master(`customer`,`cust_desc`,`user_name`,`password`) values ('$company_name','$cust_desc','$uname','$pass_encoded')";

		$sql_res=mysql_query($sql);			

		$s="select max(customer_id) from customer_master";
		$s_res=mysql_query($s);
		$r=mysql_fetch_array($s_res);
		extract($r);
		$cu=$r['max(customer_id)'];
		
		 if($sql_res)
		 {

				$setuserid=mysql_query("update customer_master set usertypeid=concat('O',$cu) where customer_id=$cu");
				$sql1="insert into customer_contact(`customer_id`,`customer_name`,`mobile`,`address`) values (concat('O',$cu),'$contactname','$mob','$add')";
				echo $sql1;

				$sql_res1=mysql_query($sql1);	 
		 }


		

if($sql_res1)
	{
		if(isset($_POST['submit']) && $_FILES['uploadedfile']['size'] > 0)
			{

				$fileName = $_FILES['uploadedfile']['name'];
				$tmpName = $_FILES['uploadedfile']['tmp_name'];
				$fileSize = $_FILES['uploadedfile']['size'];
				$fileType = $_FILES['uploadedfile']['type'];

				$fp      = fopen($tmpName, 'r');
				$content = fread($fp, filesize($tmpName));
				$content = addslashes($content);
				fclose($fp);

				if(!get_magic_quotes_gpc())
				{
					$fileName = addslashes($fileName);
				}


				$query = "INSERT INTO customer_logo (customer_id,name, size, type, content,uploaded_on) VALUES (concat('O',$cu),'$fileName', '$fileSize', '$fileType', '$content',sysdate())";


				mysql_query($query) or die('Error, query failed'); 

				
			}

	}

			
		if($sql_res1)
		{
		 header("location:view-customers.php");
		}

?>